//
//  PromotionCell.m
//  TerritoryShopkeeper
//
//  Created by xiaowu on 2017/12/13.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "PromotionCell.h"
#import "PronmotionItemView.h"

@implementation PromotionCell

+ (CGFloat)getHeight:(NSMutableArray <PromotionModel *> *)arr {
    CGFloat height = 0;
    if (arr.count > 0) {
        height += 12 + 20 + 12;
        if (arr.count > 1) {
            height += 25 * (arr.count - 1);
        }
    }
    return height;
}

- (void)setValueForCellWithValue:(NSMutableArray <PromotionModel *> *)arr {
    
    if (arr.count == 0) {
        [self.rightArrowImage setHidden:YES];
        [self.titleLabel setHidden:YES];
        [self.lineView setHidden:YES];
    } else {
        [self.rightArrowImage setHidden:NO];
        [self.titleLabel setHidden:NO];
        [self.lineView setHidden:NO];
    }
    
    for (UIView *view in self.contentView.subviews) {
        if ([view isKindOfClass:[PronmotionItemView class]]) {
            [view removeFromSuperview];
        }
    }
    
    CGFloat labelHeight = 20;
    CGFloat labelComment = 5;
    CGFloat startY = 12;
    for (NSInteger i = 0; i < arr.count; i++) {
        PromotionModel *promotionModel = [arr objectAtIndex:i];
        
        PronmotionItemView *item = [[PronmotionItemView alloc] init];
        item.frame = CGRectMake(10 + 30 + 10, startY, self.width - self.titleLabel.right-10-34, labelHeight);
        
        [item setValueForView:promotionModel];
        
        [self.contentView addSubview:item];
        startY += (labelComment + labelHeight);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.titleLabel.font = TextPingFangFontSize(14);
    self.titleLabel.textColor = [UIColor grayTextColor];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
